package com.org.controller.pc;

import com.org.DTO.PageDTO;
import com.org.DTO.SearchItemsDTO;
import com.org.entity.SearchItems;
import com.org.message.BaseMessage;
import com.org.result.Result;
import com.org.service.SearchItemsService;
import com.org.vo.PageResult;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * 寻物启事控制器
 */
@RestController
@Slf4j
@RequiredArgsConstructor
@RequestMapping("/pc/searchItems")
public class SearchItemsController {

    private final SearchItemsService searchItemsService;

    /**
     * 分页查询指定区域下的所有寻物启事信息
     * @param pageDTO
     * @return
     */
    @GetMapping("/findAllPage")
    public Result<PageResult> findAllPage(PageDTO pageDTO) {
        return Result.success(searchItemsService.findAllPage(pageDTO));
    }

    /**
     * 添加寻物启事信息
     * @param searchItemsDTO
     * @return
     */
    @PostMapping("/add")
    public Result<String> addSearchItems(@RequestBody SearchItemsDTO searchItemsDTO) {
        log.info("添加的寻物启事信息为{}", searchItemsDTO);
        searchItemsService.addSearchItems(searchItemsDTO);
        return Result.success("添加成功");
    }

    /**
     * 根据Id查询寻物启事信息
     * @param id
     * @return
     */
    @GetMapping("/findById")
    public Result<SearchItems> findById(Long id) {
        return Result.success(searchItemsService.findSearchItemsById(id));
    }

    /**
     * 修改寻物启事信息
     * @param searchItemsDTO
     * @return
     */
    @PutMapping("/update")
    public Result<String> updateSearchItems(@RequestBody SearchItemsDTO searchItemsDTO) {
        log.info("修改的寻物启事信息为{}", searchItemsDTO);
        searchItemsService.updateSearchItems(searchItemsDTO);
        return Result.success("修改成功");
    }

    /**
     * 删除寻物启事信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Result<String> deleteSearchItems(@PathVariable("id") Long id) {
        log.info("删除的寻物启事ID为{}", id);
        searchItemsService.deleteSearchItemsById(id);
        return Result.success("删除成功");
    }

    /**
     * 修改寻物启事信息状态
     * @param id
     * @return
     */
    @GetMapping("/updateStatus")
    public Result<String> updateStatus(Long id, Long status) {
        log.info("修改ID为 {} 的寻物启事状态为{}", id, status);
        searchItemsService.updateStatus(id, status);
        return Result.success(BaseMessage.UPDATE_SUCCESS);
    }
}
